package com.antoco.controlcenter.model.video.biz;


import com.antoco.controlcenter.base.BaseBiz;
import com.antoco.controlcenter.http.observer.HttpRxCallback;
import com.antoco.controlcenter.http.retrofit.HttpRequest;
import com.antoco.controlcenter.model.video.entity.OsdEntity;
import com.google.gson.Gson;
import com.trello.rxlifecycle2.LifecycleProvider;

import java.util.TreeMap;

public class OsdBiz extends BaseBiz {
    /**
     * osd
     */
    private final String API_LOGIN = "/cgi-bin/domecontrol_cgi/";

    public void startOsdParm(String action, String userName, String pwdword, String title, String presetNum, LifecycleProvider lifecycle, HttpRxCallback callback) {
        /**
         * 构建参数
         */
        TreeMap<String, Object> request = new TreeMap<>();
        request.put("action", action);
        request.put("user", userName);
        request.put("pwd", pwdword);
        request.put("Title", title);
        request.put("PresetNum", presetNum);
        request.put(HttpRequest.API_URL, API_LOGIN);

        /**
         * 解析数据
         */
        callback.setParseHelper(jsonElement -> {
            OsdEntity bean = new Gson().fromJson(jsonElement, OsdEntity.class);
            Object[] obj = new Object[1];
            obj[0] = bean;
            return obj;
        });

        /**
         * 发送请求
         */
        getRequest().request(HttpRequest.Method.GET, request, lifecycle, callback);
    }
}
